from app.extensions import db
from datetime import datetime

class SystemLog(db.Model):
    __tablename__ = 'system_logs'

    id = db.Column(db.Integer, primary_key=True)
    level = db.Column(db.String(20), nullable=False)  # 日志级别：INFO, WARN, ERROR等
    message = db.Column(db.Text, nullable=False)      # 日志内容
    timestamp = db.Column(db.DateTime, default=datetime.now, nullable=False)  # 时间戳

    def to_dict(self):
        return {
            'id': self.id,
            'level': self.level,
            'message': self.message,
            'timestamp': self.timestamp.isoformat()
        }